// 导入路由： constantRoutes 静态路由 & 动态路由
import { constantRoutes, asyncRouters } from '../../router/index.js'

const state = {
  // 当前用户的权限
  // 保存静态路由
  routers: constantRoutes
}
const mutations = {
  // 设置动态路由
  setRouters (state, payload) {
    // 将动态路由与静态路由进行合并
    state.routers = [...constantRoutes, ...payload]
  }
}
const actions = {
    setRoutes(context, menus){
        const newMenus =  asyncRouters.filter(item => {
            return menus.some(value => {
                // 判断登录用户的权限路由与动态路由进行匹配
                return item.name == value
            })
        })
        context.commit('setRouters', newMenus)
        return newMenus
    }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
